<template>
  <div class="app-container"
    v-loading.fullscreen.lock="loading"
    element-loading-text="Loading"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.7)"
    element-loading-customClass='mask'>
    <el-tabs v-model="currentIndex" type="card" @tab-click="handleclick">
      <el-tab-pane
        v-for="(item, index) in commands"
        :key="index"
        :name="index.toString()"
        :label="item.name"
      >
      </el-tab-pane>
    </el-tabs>
    <el-button
      v-if="portalItemId != 7"
      style="position: absolute; right: 0; top: 0; z-index: 1000"
      @click="handleToggleExpand()"
      ><svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'"
    /></el-button>
    <el-row
      :style="
        'height: calc(100% - 56px);margin-left:' +
        (treeMenu.length > 0 && !show ? '14px' : '0') +
        ';margin-right:' +
        (treeMenu.length > 0 && !show ? '14px' : '0;')
      "
    >
      <el-col
        v-if="treeMenu.length > 0 && show"
        :span="3"
        :xs="24"
        class="treeMenu"
      >
        <el-button
          class="collapesbutton"
          type="primary"
          plain
          style="right: 1px; top: 50px; height: 10%"
          @click="show = !show"
        >
          <i
            :class="show ? 'el-icon-d-arrow-left' : 'el-icon-d-arrow-right'"
          ></i>
        </el-button>
        <el-tabs
          type="border-card"
          v-model="activeName"
          v-if="treeMenu.length > 0 && show"
        >
          <el-tab-pane
            name="treeMenu"
            v-if="treeMenu.length > 0"
            style="padding: -15px"
          >
            <span slot="label"><i class="el-icon-tickets"></i></span>
            <el-menu
              style="padding: 0"
              :default-active="activeIndex"
              class="el-menu-vertical"
            >
              <el-menu-item
                v-for="(item, i) in treeMenu"
                :key="i"
                :index="i.toString()"
                @click="handleOpen(item, i)"
              >
                <i :class="item.icon"></i>
                <span slot="title" :title="item.name">{{ item.name }}</span>
              </el-menu-item>
            </el-menu>
          </el-tab-pane>
          <el-tab-pane
            name="treeData"
            v-if="treeData.length > 0"
            style="padding: -15px"
          >
            <span slot="label">
              <svg-icon icon-class="tree-table" />
            </span>
            <dynamic-tree
              ref="dynamicTree"
              :treeData="treeData"
              @handleNodeClick="handleNodeClick"
            >
            </dynamic-tree>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col
        :span="treeMenu.length > 0 && show ? 21 : 24"
        :xs="24"
        style="padding: 0; height: 100%"
      >
        <div class="mainContent">
          <template v-if="chart == 'monitor'">
            <el-tabs type="border-card" style="height: 100%">
              <el-tab-pane label="阶段门">
                <stage-gate :geturl="menuUrl" :table="table"></stage-gate>
              </el-tab-pane>
              <el-tab-pane label="甘特图">
                <gantt-chart />
              </el-tab-pane>
            </el-tabs>
          </template>
          <template v-else-if="chart != 'lifeCycle'">
            <!-- <report/> -->
            <component :is="chart" :root="root"></component>
          </template>
          <template v-if="portal">
            <item-portal-view :params="portal" :root="root" />
          </template>
          <template v-else>
            <el-row v-if="formData.length > 0" class="mb10" ref="formList">
              <el-col>
                <el-button
                  v-if="!updateShow"
                  style="margin-bottom: 10px"
                  type="success"
                  icon="el-icon-edit"
                  size="mini"
                  @click="updateShow = true"
                  >修改</el-button
                >
                <div v-if="updateShow" style="margin-bottom: 10px">
                  <el-button
                    type="primary"
                    icon="el-icon-circle-check"
                    size="mini"
                    @click="handleSaveForm"
                    >保存</el-button
                  >
                  <el-button
                    type="info"
                    icon="el-icon-refresh"
                    size="mini"
                    @click="updateShow = false"
                    >取消</el-button
                  >
                </div>
              </el-col>
              <el-col
                class="flex"
                v-for="(from, index) in formData"
                :key="index"
              >
                <template v-if="index % 2 == 0">
                  <span class="extendedMain fromTitle">
                    {{ from.name }}：
                  </span>
                  <div class="extendedMain content" v-if="updateShow">
                    <dynamic-form-Item
                      :addform="[from]"
                      :form="menuDataInfo"
                    ></dynamic-form-Item>
                  </div>
                  <span v-else class="extendedMain content">
                    {{ dataFormat(from.prop, menuDataInfo[from.prop]) }}
                  </span>
                  <template v-if="index != formData.length - 1">
                    <span class="extendedMain fromTitle">
                      {{ formData[index + 1].name }}：
                    </span>
                    <div class="extendedMain content" v-if="updateShow">
                      <dynamic-form-Item
                        :addform="[formData[index + 1]]"
                        :form="menuDataInfo"
                      ></dynamic-form-Item>
                    </div>
                    <span v-else class="extendedMain content">
                      {{
                        dataFormat(
                          formData[index + 1].prop,
                          menuDataInfo[formData[index + 1].prop]
                        )
                      }}
                    </span>
                  </template>
                  <template v-if="index == formData.length - 1">
                    <span class="extendedMain fromTitle"></span>
                    <span class="extendedMain content"></span>
                  </template>
                </template>
              </el-col>
            </el-row>
            <template v-if="chart == 'lifeCycle'">
              <life-cycle
                :geturl="menuUrl"
                :parent="root"
                ref="lifeCyle"
              ></life-cycle>
            </template>
            <el-row class="mb8">
              <el-col :span="15" v-if="root.operational !== '0'">
                <div
                  v-for="(toolbar, index) in toolbarData"
                  :key="index"
                  style="display: inline-block"
                >
                  <template
                    v-if="
                      (toolbar.info.display == 0 && toolbar.data.length >= 4) ||
                      toolbar.info.display == 2
                    "
                  >
                    <el-dropdown
                      style="padding: 0; margin-right: 10px; margin-left: 10px"
                    >
                      <el-button type="primary" size="mini">
                        <i :class="toolbar.info.icon"></i>
                        {{ toolbar.info.description }}
                        <i class="el-icon-arrow-down"></i>
                      </el-button>
                      <el-dropdown-menu slot="dropdown">
                        <div v-for="(btn, key) in toolbar.data" :key="key">
                          <el-dropdown-item
                            v-if="btn.status === '1' && btn.location === '2'"
                          >
                            <el-button
                              size="mini"
                              type="text"
                              :icon="btn.icon"
                              v-preventReClick
                              :disabled="
                                btn.show != null &&
                                btn.show != undefined &&
                                btn.show != ''
                                  ? !dynamicEval($data, btn.show)
                                  : false
                              "
                              @click="clickEvent(btn)"
                              >{{ btn.name }}</el-button
                            >
                          </el-dropdown-item>
                        </div>
                      </el-dropdown-menu>
                    </el-dropdown>
                  </template>
                  <template
                    v-if="
                      (toolbar.info.display == 0 && toolbar.data.length < 4) ||
                      toolbar.info.display == 1
                    "
                  >
                    <div
                      v-for="(btn, index) in toolbar.data"
                      :key="index"
                      style="display: inline-block; margin: 0 3px"
                    >
                      <template v-if="btn.name == '全编辑'">
                        <el-button
                          v-if="!editall"
                          :type="btn.styleType"
                          :icon="btn.icon"
                          size="mini"
                          @click="clickEvent(btn)"
                          >{{ btn.name }}
                        </el-button>
                        <el-button
                          type="primary"
                          size="mini"
                          @click="subEditAll()"
                          v-if="editall"
                          >保存</el-button
                        >
                        <el-button
                          type="info"
                          size="mini"
                          @click="cancelEditAll()"
                          v-if="editall"
                          >取消</el-button
                        >
                      </template>
                      <template v-else>
                        <el-button
                          v-if="btn.status === '1' && btn.location === '2'"
                          :type="btn.styleType"
                          :icon="btn.icon"
                          size="mini"
                          v-preventReClick
                          :disabled="
                            btn.show != null &&
                            btn.show != undefined &&
                            btn.show != ''
                              ? !dynamicEval($data, btn.show)
                              : false
                          "
                          @click="clickEvent(btn)"
                          >{{ btn.name }}
                        </el-button>
                      </template>
                    </div>
                  </template>
                </div>
              </el-col>
              <!-- 列筛选 -->
              <el-popover
                v-if="columns.length > 0 && chart != 'lifeCycle'"
                title="列筛选"
                trigger="click"
                style="float: right; margin-right: 10px"
              >
                <el-checkbox
                  style="display: block"
                  v-for="(item, index) in columns"
                  :key="index"
                  :label="item.name"
                  v-model="item.show"
                  >{{ item.name }}
                </el-checkbox>
                <el-button size="small" slot="reference">
                  <i class="el-icon-arrow-down el-icon-menu"></i>
                </el-button>
              </el-popover>
      <el-form
        :inline="true"
        :model="queryParams"
        ref="queryForm"
        label-width="100"
        style="float: right"
        @submit.native.prevent
      >
        <el-form-item
          v-if="searchFormData.length != 0 && searchFormData[0].status === '1'"
          :key="searchFormData[0].prop"
          :label="searchFormData[0].name"
        >
          <el-input
            size="small"
            v-model="queryParams[searchFormData[0].prop]"
            :placeholder="'请输入' + searchFormData[0].name"
            clearable
            @keyup.enter.native="handleQuery"
          >
          </el-input>
        </el-form-item>
        <el-form-item v-if="searchFormData.length != 0">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            v-preventReClick
            @click="handleQuery"
            >搜索
          </el-button>
          <el-button
            type="info"
            icon="el-icon-refresh"
            size="mini"
            v-preventReClick
            @click="resetQuery"
            >重置
          </el-button>
          <el-button
            v-if="searchFormData.length > 1"
            icon="el-icon-arrow-down"
            size="mini"
            id="more-attr"
            v-preventReClick
            @click="moreattr"
            >更多属性
          </el-button>
        </el-form-item>
        <div id="more-list" style="display: none">
          <el-form-item
            v-for="item in searchFormData.slice(1)"
            :key="item.prop"
            :label="item.name"
          >
            <div v-if="item.status === '1'">
              <!--根据type来显示是什么标签-->
              <el-select
                v-model="queryParams[item.prop]"
                placeholder="请选择"
                v-if="item.componentType === 'el-select'"
              >
                <el-option
                  v-for="item in item.optionValue"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
              <el-date-picker
                v-model="queryParams[item.prop]"
                size="small"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                v-if="item.componentType === 'el-date-picker'"
              ></el-date-picker>
              <el-input
                size="small"
                v-model="queryParams[item.prop]"
                :placeholder="'请输入' + item.name"
                v-else
              >
              </el-input>
            </div>
          </el-form-item>
        </div>
      </el-form>
              <!-- 列筛选 -->
            </el-row>
            <template v-if="columns.length > 0">
              <!--列表数据-->
              <dynamic-tree-table
                ref="treeTable"
                v-if="type == 'tree_table'"
                :list="tableData"
                @ContextMenu="Opencontextmenu($event)"
                @handleSelectionChange="handleSelectionChange"
                @editChanged="editChanged($event)"
                @openTable="openTable($event)"
                @SetFlag="SetFlag()"
                :options="options"
                :columns="columns"
                :operates="operates"
                :flag="flag"
                :diff="diff"
              >
              </dynamic-tree-table>
              <template v-else>
                <dynamic-table
                  ref="dyTable"
                  :list="tableData"
                  @updateList="getMenuConfig"
                  @handleSelectionChange="handleSelectionChange"
                  @editChanged="editChanged($event)"
                  @openTable="openTable($event)"
                  @handleNodeClick="handleNodeClick"
                  :options="options"
                  :columns="columns"
                  :operates="operates"
                  :diff="diff"
                >
                </dynamic-table>
                <pagination
                  v-show="total > 0"
                  :total="total"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
                  ref="pagination"
                />
              </template>
            </template>
          </template>
        </div>
      </el-col>
    </el-row>

    <ul
      v-show="contextmenu.visible"
      :style="{ left: contextmenu.left + 'px', top: contextmenu.top + 'px' }"
      class="contextmenu"
    >
      <template
        v-if="
          this.ids.length > 0 &&
          this.tableData &&
          this.tableData.length <= this.copy_table.length
        "
      >
        <li @click="copy('copy')">复制所选项及所有子项</li>
        <li @click="copy('cut')">剪切所选项及所有子项</li>
        <template v-if="this.copy_ids.length > 0">
          <li @click="paste(1)">粘贴为子项</li>
          <li @click="paste(0)">粘贴为同级</li>
        </template>
      </template>
      <li
        v-if="
          this.ids.length <= 0 &&
          this.tableData &&
          this.tableData.length <= this.copy_table.length
        "
      >
        未选中任何数据
      </li>
      <template
        v-if="this.tableData && this.tableData.length > this.copy_table.length"
      >
        <li @click="submit()">保存编辑</li>
        <li @click="reset()">重置</li>
      </template>
    </ul>
    <!-- 添加或修改对话框 -->
    <el-dialog
      ref="addForm"
      :title="title"
      :visible.sync="open"
      width="50%"
      v-dialogDrag
      :close-on-click-modal="false"
      v-if="open"
    >
      <dynamic-form
        :addform="addFormData"
        :form="form"
        :rules="rules"
        :addurl="addurl"
        v-on:openChanged="openChanged($event)"
        @loadingOpen="handleLoadingOpen"
        @loadingClose="loading = false"
      >
      </dynamic-form>
    </el-dialog>
    <!-- 添加或修改对话框 -->
    <!-- 添加或修改对话框 -->
    <el-dialog
      ref="formTable"
      :title="title"
      :visible.sync="topen"
      width="80%"
      v-dialogDrag
      :close-on-click-modal="false"
      v-if="topen"
    >
      <dynamic-form-table
        :exsitId="exsitId"
        :geturl="geturl"
        :submiturl="addurl"
        @openTable="openTable($event)"
        @topenChanged="topenChanged($event)"
        @loadingOpen="handleLoadingOpen"
        @loadingClose="loading = false"
        @clickEvent="clickEvent"
        @updateIds="setIds"
        @subBatch="subBatch"
        :table="table"
        :toolbar="toolbar"
        :form="form"
        :search="search"
      >
      </dynamic-form-table>
    </el-dialog>
    <!-- 二级对话框 -->
    <el-dialog
      ref="subAddForm"
      :title="subtitle"
      :visible.sync="subopen"
      width="50%"
      v-dialogDrag
      :close-on-click-modal="false"
      v-if="subopen"
    >
      <dynamic-form
        :addform="addFormData"
        :form="form"
        :rules="rules"
        :addurl="addurl"
        @loadingOpen="handleLoadingOpen"
        @loadingClose="loading = false"
        v-on:openChanged="openChanged($event)"
      >
      </dynamic-form>
    </el-dialog>
    <!-- 二级对话框 -->
    <!-- 二级对话框 -->
    <el-dialog
      ref="subFormTabel"
      :title="subtitle"
      :visible.sync="subtopen"
      width="80%"
      v-dialogDrag
      :close-on-click-modal="false"
      v-if="subtopen"
    >
      <dynamic-form-table
        :exsitId="exsitId"
        :geturl="geturl"
        :submiturl="addurl"
        @loadingOpen="handleLoadingOpen"
        @loadingClose="loading = false"
        @closeTable="closeTable($event)"
        @topenChanged="topenChanged($event)"
        @clickEvent="clickEvent"
        @updateIds="setIds"
        :table="table"
        :toolbar="toolbar"
        :command="command"
        :form="form"
        :search="search"
      >
      </dynamic-form-table>
    </el-dialog>
    <!-- 导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
      v-dialogDrag
      :close-on-click-modal="false"
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <item-portal-dialog
      :params="portaldialog"
      v-if="portaldialog.open"
      :root="root.dataInfo == undefined ? {...this,operational:root.operational} : root"
    />
  </div>
</template>
<script>
import {
  baseRequest,
  getDataList,
  getConfigInfo,
  getData,
  getAddForm,
  delData,
  exportData,
  getTreeCommand,
  getEsData,
  updateData,
  upgrade,
  addData,
} from "@/api/dynamic/dynamic";
import { getCommandData } from "@/api/pms/dynamic";
import dynamicTable from "@/views/components/dynamicTable";
import dynamicForm from "@/views/components/dynamicForm";
import dynamicTree from "@/views/components/dynamicTree";
import dynamicFormTable from "@/views/components/dynamicFormTable";
import dynamicTreeTable from "@/views/components/dynamicTreeTable";
import { deepClone, filter2sub } from "@/utils";
import commonFun from "@/views/mixins/commonFun";

export default {
  name: "portalItem",
  components: {
    dynamicForm,
    dynamicTable,
    dynamicTree,
    dynamicFormTable,
    dynamicTreeTable,
    dynamicFormItem: () => import("@/views/components/dynamicFormItem"),
    ganttChart: () => import("@/views/components/gantt/index"),
    stageGate: () => import("@/views/components/stageGate"),
    report: () => import("@/views/pms/report"),
    lifeCycle: () => import("@/views/components/lifeCycle"),
    resizeBar: () => import("@/views/components/resizeBar"),
    itemPortalDialog: () => import("@/views/components/portalDialog"),
    itemPortalView: () => import("@/views/portal/index"),
    processReview: () => import("@/views/components/processReview"),
    flowChart: () => import("@/views/components/flowChart"),
  },
  mixins: [commonFun],
  props: {
    pageParams: null,
    rowParams: {
      type: Object,
      default: () => {},
    },
    portalItemId: 0,
    root: null,
  },
  data() {
    return {
      isMyobject: true,
      // loading: false,
      updateShow: false,
      //所选项id
      // ids: [],
      copy_ids: [],
      // 所选项
      // selected: [],
      // 粘贴提交数据容器
      subPasteData: [],
      pasteType: 1,
      // // 弹出层标题
      // title: "",
      // subtitle: "",
      // // 是否显示弹出层
      // open: false,
      // subopen: false,
      // topen: false,
      // subtopen: false,
      show: true,
      flag: true,
      // total: 0,
      allData: [],
      pageTitle: "",
      url: "",
      menuUrl: "",
      params: {},
      searchFormData: [],
      toolbarData: [],
      commandData: [],
      commands: [],
      currentIndex: "0",
      formData: [],
      tableData: [],
      copy_table: [],
      treeMenu: [],
      treeData: [],
      columns: [], // 需要展示的列
      queryParams: {},
      configQueryParams: {},
      queryMenuParams: {},
      dataInfo: {},
      menuDataInfo: {},
      listQuery: {
        pageNum: 1,
        pageSize: this.$store.state.user.pageSize||30,
      },
      // operates: {
      //   // 列操作按钮
      //   width: 150,
      //   list: [],
      // },
      queryTreeParams: {},
      activeName: "treeMenu",
      activeIndex: "0",
      menuData: "",
      // form: {},
      // rules: {},
      // addFormData: [],
      // addurl: "",
      copy_url: "",
      treeStr: "",
      projectid: 0,
      parentid: "",
      type: "",
      exsitId: [],
      geturl: "",
      table: "",
      toolbar: "",
      chart: "",
      portal: "",
      btntype: "",
      moduleName: "",
      editall: false,
      contextmenu: {
        visible: false,
        top: 0,
        left: 0,
      },
      portaldialog: {
        open: false,
        title: "编辑",
        portal: {},
      },
      isFullscreen: false,
      parentid: 0,
      diff: 0,
      dif: 0,
      update: 0,
      search: 'full_search'
    };
  },
  created() {
    this.projectid = this.$route.params.Id;
    this.getDataInfo();
  },
  updated() {
    let ele = this.$refs.dyTable || this.$refs.treeTable;
    if (ele && this.update>-1) {
      this.update =-1;
      this.diff = 100;
      this.dif = 0
      for (let x in this.$refs) {
        if (x.indexOf("Table") == -1) {
          let h = this.$refs[x]?(this.$refs[x].$el?this.$refs[x].$el.offsetHeight:this.$refs[x].offsetHeight):0;
          // let h=30
          if(x.indexOf("topInfo") > -1){
            this.dif += h;
          }
          this.diff += h;
        }
      }
      // ele.tableresize()
    }
  },
  mounted() {
    // if(this.root ==null){this.root = this}
    // if (this.root && this.root.isMyobject != undefined) {
    //   this.isMyobject = this.root.isMyobject;
    // }
    this.currentIndex =
      sessionStorage.getItem(this.$route.path + this.portalItemId) || "0";
    this.parentid = this.root.parentid || this.projectid;
  },
  watch: {
    pageParams: {
      immediate: true,
      handler(val) {
        if (val) {
          if (Array.isArray(val)) {
            this.configQueryParams.command = val.join(",");
            this.getConfig(false);
          } else {
            this.getConfig(true);
          }
        }
      },
    },
  },
  methods: {
    /** 获取配置信息 */
    getConfig(flag) {
      // this.loading = true;
      if (flag)
        getCommandData("/pms/command/portal/" + this.pageParams).then(
          (response) => {
            this.commands = response.data;
            // this.loading = false;
            let i = this.currentIndex;
            this.handleOpen(this.commands[i]);
          }
        );
      else
        getConfigInfo(this.configQueryParams).then((response) => {
          this.commands = response.data.commandData;
          // this.loading = false;
          let i = this.currentIndex;
          this.handleOpen(this.commands[i]);
        });
    },
    handleclick(tab, event) {
      sessionStorage.setItem(this.$route.path + this.portalItemId, tab.name);
      this.handleOpen(this.commands[tab.name]);
    },
    getMenuConfig(type) {
      this.flag = true;
      // this.loading = true;
      type = type ? type : this.type;
      getConfigInfo(this.queryMenuParams).then((response) => {
        this.columns = response.data.tableData;
        for(let index in response.data.tableData){
          let item = response.data.tableData[index]
          if(item.propType=='dynamic'){
            getDataList(this.getUrl(item.url,this.$data)).then(res=>{
                this.columns.splice(index,1,...res.rows)
            })
          }
        }
        // if (response.data.tableData.length > 0) {
        //   this.updateTempDicts(response.data.tableData);
        // }
        this.formData = response.data.showFormData;
        this.searchFormData = response.data.searchFormData;
        this.formData = this.formData.filter(
          (item) =>
            item.status == "1" &&
            (item.show != null && item.show != undefined && item.show != ""
              ? this.dynamicEval(this.params.rowParams, item.show)
              : true)
        );
        // if (response.data.showFormData.length > 0) {
        //   this.updateTempDicts(response.data.showFormData);
        // }
        this.operates.list = response.data.commandData;
        this.toolbarData = response.data.toolbarData;
        // this.loading = false;
        if (this.btntype === 3) {
          this.getESData();
        } else if (this.menuUrl) {
          this.getMenuDataInfo(type);
        }
      });
    },
    getDataInfo() {
      let type = this.$route.query.type;
      if (type == undefined) type = "/pmswbs";
      if (type.indexOf("}") == -1) {
        if (this.projectid) {
          getData(type, this.projectid).then((response) => {
            if (response.code == 200) {
              this.dataInfo = response.data;
            } else {
              this.$message.error(response.msg);
            }
          });
        }
      }
    },
    getMenuDataInfo(type) {
      // this.loading = true;
      this.getDataInfo();
      if (type == "form") {
        this.menuDataInfo = deepClone(this.dataInfo);
      } else if (type == "tree") {
        getDataList(this.menuUrl).then((response) => {
          this.tableData = response.rows;
          this.copy_table =
            this.tableData.length > 0 ? deepClone(this.tableData) : [];
          this.total = response.total;
          if (this.treeStr) {
            let dataArray = response.rows;
            var treeInfo = {};
            treeInfo.id = this.dataInfo.id;
            treeInfo.label = this.dataInfo.name;
            treeInfo.children = [];
            treeInfo.url = "";
            treeInfo.pageParams = "";
            treeInfo.parentid = -1;
            this.treeData = [];
            this.treeData.push(treeInfo);

            getTreeCommand({ command: this.treeStr }).then((response) => {
              this.commandData = response.data;
              this.treeData[0].url = this.commandData[0].url;
              this.treeData[0].pageParams = this.commandData[0].pageParams;
              if (this.commandData.length > 0) {
                dataArray.forEach((item, index) => {
                  if (this.commandData[1]) {
                    dataArray[index].url = this.commandData[1].url;
                    dataArray[index].pageParams =
                      this.commandData[1].pageParams;
                  } else {
                    dataArray[index].url = this.commandData[0].url;
                    dataArray[index].pageParams =
                      this.commandData[0].pageParams;
                  }
                  dataArray[index] = this.normalizer(item);
                });
                this.treeData[0].children = this.handleTree(dataArray, "id");
                this.activeName = "treeData";
              }
            });
          }
          // this.loading = false;
        });
      } else if (type == "tree_table") {
        getDataList(this.menuUrl).then((response) => {
          this.tableData = [];
          // if(JSON.stringify(this.dataInfo)!="{}"){
          //   this.tableData.push(this.dataInfo);
          // }
          this.tableData = this.tableData.concat(response.rows);
          this.copy_table =
            this.tableData.length > 0 ? deepClone(this.tableData) : [];
          // this.loading = false;
        });
      } else {
        this.queryParams = {
          pageNum: 1,
          pageSize: this.$store.state.user.pageSize||30,
        };
        this.dataUrl = this.menuUrl;
        getDataList(this.menuUrl, this.queryParams).then((response) => {
          this.tableData = response.rows;
          if (response.rows.length > 0)
            this.copy_table = this.tableData.concat();
          this.total = response.total;
          // this.loading = false;
        });
      }
    },
    /** 从ES中获取数据 */
    getESData() {
      getEsData(this.projectid, this.moduleName, this.operation).then(
        (response) => {
          let EsData = response.hits.hits;
          let EsTableData = [];
          EsData.forEach((item) => {
            EsTableData.push(item._source);
          });
          this.tableData = EsTableData;
          this.copy_table =
            this.tableData.length > 0 ? deepClone(this.tableData) : [];
          this.total = response.hits.total;
        }
      );
    },
    /** 获取树菜单配置 */
    getTreeConfig() {
      // this.loading = true;
      getConfigInfo(this.queryTreeParams).then((response) => {
        this.columns = response.data.tableData;
        // if (response.data.tableData.length > 0)
        //   this.updateTempDicts(response.data.tableData);
        this.searchFormData = response.data.searchFormData;
        if (
          this.root.params.rowParams.operational !== "0" &&
          this.root.operational !== "0"
        ) {
          this.toolbarData = response.data.toolbarData;
          this.operates.list = response.data.commandData;
        }
        // this.loading = false;
      });
    },
    /** 获取列表数据 */
    getList() {
      // this.loading = true;
      getDataList(this.dataUrl, this.queryParams).then((response) => {
        this.tableData = response.rows;
        this.copy_table =
          this.tableData.length > 0 ? deepClone(this.tableData) : [];
        this.total = response.total;
        // this.loading = false;
      });
    },
    handleLoadingOpen(){
      this.loading = true;
      setTimeout(()=>{this.openChanged();this.topenChanged()},30000);
    },
    handleOpen(item, i) {
      this.formData = [];
      this.columns = [];
      this.treeData = [];
      this.toolbarData = [];
      this.tableData = [];
      this.operates.list = [];
      this.queryMenuParams = {};
      this.treeStr = "";
      this.chart = "";
      this.portal = false;
      this.btntype = "";
      let pageParams = JSON.parse(item.pageParams.replace(/'/g, '"'));
      if (item.type === "3") {
        this.btntype = 3;
        this.moduleName = pageParams.moduleName
          ? pageParams.moduleName
          : this.$route.query.type == "pmsproject"
          ? "项目管理"
          : this.$route.query.type == "doc"
          ? "文档管理"
          : "";
        this.operation = pageParams.operation ? pageParams.operation : "";
      }
      this.$set(this.params, "currentIndex", i);
      sessionStorage.setItem(
        "details" + this.projectid,
        JSON.stringify(this.params)
      );
      if (pageParams.chart !== "" && pageParams.chart !== undefined) {
        this.chart = pageParams.chart;
        if (this.chart != "lifeCycle") return;
        if (item.url) {
          this.menuUrl = this.getUrl(item.url);
        }
        this.table = pageParams.table;
        this.toolbar = pageParams.toolbar;
      }
      if (pageParams.portal !== "" && pageParams.portal !== undefined) {
        this.portal = { portal: pageParams.portal };
        return;
      }
      if (pageParams.table !== "" && pageParams.table !== undefined) {
        this.queryMenuParams.table = pageParams.table;
      }
      if (pageParams.toolbar !== "" && pageParams.toolbar !== undefined) {
        this.queryMenuParams.toolbar = pageParams.toolbar;
      }
      if (pageParams.command !== "" && pageParams.command !== undefined) {
        this.queryMenuParams.command = pageParams.command;
      }
      if (pageParams.searchForm !== "" && pageParams.searchForm !== undefined) {
        this.queryMenuParams.searchForm = pageParams.searchForm;
      }
      if (pageParams.showForm !== "" && pageParams.showForm !== undefined) {
        this.queryMenuParams.showForm = pageParams.showForm;
        const params = JSON.parse(sessionStorage.getItem(this.$route.path))
        this.menuDataInfo = deepClone(params.rowParams);
      }
      if (
        pageParams.treeCommand !== "" &&
        pageParams.treeCommand !== undefined
      ) {
        this.treeStr = pageParams.treeCommand;
      }
      if (item.url) {
        this.menuUrl = this.getUrl(item.url, this.$data);
      } else {
        this.menuUrl = null;
      }
      this.type = pageParams.type ? pageParams.type : "table";
      this.getMenuConfig(this.type);
    },
    // 数据排序
    SortList(val) {
      val.sort(function (list1, list2) {
        let list1_rank = list1.rank ? list1.rank.trim().split(".") : [0];
        let list2_rank = list2.rank ? list2.rank.trim().split(".") : [0];
        for (let i = 0; ; i++) {
          if (list1_rank[i] == undefined && list2_rank[i] == undefined)
            return true;
          list1_rank[i] =
            list1_rank[i] == undefined ? 0 : Number(list1_rank[i]);
          list2_rank[i] =
            list2_rank[i] == undefined ? 0 : Number(list2_rank[i]);
          if (list1_rank[i] - list2_rank[i] != 0) {
            return list1_rank[i] - list2_rank[i];
          }
        }
      });
    },
    //查询按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //重置
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: this.$store.state.user.pageSize||30,
      };
      this.handleQuery();
    },
    // // 按钮点击事件操作
    // clickEvent(obj) {
    //   if (obj.name == "全编辑") {
    //     this.editall = !this.editall;
    //     if (this.$refs.treeTable) this.$refs.treeTable.editall = this.editall;
    //     else this.$refs.dyTable.editall = this.editall;
    //     return;
    //   }
    //   if (obj.type === "2") {
    //     if (this.ids.length !== 1 && obj.location !== "2") {
    //       this.msgError("不能对没有选中或者选中多个的数据进行此项操作！");
    //       return false;
    //     }
    //     if (obj.url) {
    //       let pageParams = JSON.parse(obj.pageParams.replace(/'/g, '"'));
    //       let params = {};
    //       var pid = "";
    //       if (obj.location !== "2") pid = this.ids[0];
    //       else pid = this.projectid;
    //       pageParams.url = obj.url;
    //       pageParams.title = obj.name;
    //       pageParams.projectid = this.projectid;
    //       params.pageParams = pageParams;
    //       this.$router.push({
    //         path: "/dynamic/" + pageParams.route + "/" + pid,
    //         query: params,
    //       });
    //     }
    //   } else {
    //     this.table = "";
    //     this.toolbar = "";
    //     this.title = "";
    //     this.command = "";
    //     let pageParams = JSON.parse(obj.pageParams.replace(/'/g, '"'));
    //     // if(pageParams.condition) {
    //     //   if (!this.jugeCondition(pageParams.condition).flag){
    //     //     return false
    //     //   }
    //     // }
    //     if(pageParams.multi!=undefined) this.formMulti = pageParams.multi
    //     // this.loading = true;
    //     if (pageParams.handle == "handleDelete") {
    //       this.handleDelete(obj.url, obj.description);
    //     } else if (pageParams.handle == "handleExport") {
    //       this.handleExport(obj.url);
    //     } else if (pageParams.handle == "handleAdd") {
    //       if (pageParams.type == "table") {
    //         this.handleAddExited(obj);
    //       } else {
    //         if (obj.sub)
    //           this.handleAdd(obj.url, pageParams.addForm, obj.name, true);
    //         else this.handleAdd(obj.url, pageParams.addForm, obj.name);
    //       }
    //     } else if (pageParams.handle == "handleAddChild") {
    //       if (obj.sub)
    //         this.handleAddChild(
    //           obj.url,
    //           pageParams.addForm,
    //           obj.description,
    //           true
    //         );
    //       else
    //         this.handleAddChild(obj.url, pageParams.addForm, obj.description);
    //     } else if (pageParams.handle == "handleAddAssign") {
    //       this.handleAddAssign(obj);
    //     } else if (pageParams.handle == "handlePortal") {
    //       this.handlePortal(obj.name, pageParams.portal);
    //     } else if (pageParams.handle == "handleConfirm") {
    //       this.handleConfirm(
    //         obj.url,
    //         pageParams.method,
    //         obj.description,
    //         pageParams.condition
    //       );
    //     } else if (pageParams.handle == "handleUpdate") {
    //       if (obj.sub)
    //         this.handleUpdate(
    //           obj.url,
    //           pageParams.addForm,
    //           obj.description,
    //           true
    //         );
    //       else this.handleUpdate(obj.url, pageParams.addForm, obj.description);
    //     } else if (pageParams.handle == "handleUpgrade") {
    //       this.handleUpgrade(obj.url);
    //     } else if (pageParams.handle == "handleBatch") {
    //       this.handleBatch(obj, pageParams.addForm, pageParams.table);
    //     } else if (pageParams.handle == "handleDemotion") {
    //       this.handleDemotion(obj.url);
    //     } else if (pageParams.handle == "handleCopy") {
    //       // 新增版本
    //       this.$confirm("确认新增版本?", "提示", {
    //         confirmButtonText: "确定",
    //         cancelButtonText: "取消",
    //         type: "warning",
    //       })
    //         .then(() => {
    //           getDataList(obj.url, { id: this.$route.params.Id }).then(
    //             (response) => {
    //               if (response.code == 200) {
    //                 this.msgSuccess(response.msg);
    //                 let i = Number(this.activeIndex);
    //                 this.handleOpen(this.treeMenu[i], i);
    //                 return true;
    //               } else {
    //                 this.msgError(response.msg);
    //                 return true;
    //               }
    //             }
    //           );
    //         })
    //         .catch(() => {
    //           this.msgInfo("已取消");
    //         });
    //     } else if (pageParams.handle == "handleOpen") {
    //       let i = this.params.currentIndex;
    //       this.handleOpen(obj, i);
    //     }
    //     this.loading = false;
    //   }
    // },
    // handleConfirm(url, method, title, condition) {
    //   let jugement = this.jugeCondition(condition, url, title);
    //   if (jugement.flag) {
    //     this.$confirm(jugement.info, "提示", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //     })
    //       .then(() => {
    //         baseRequest(jugement.route, method, {}, {}).then((response) => {
    //           if (response.code == 200) {
    //             this.msgSuccess(response.msg);
    //             this.refreshCurrent();
    //             return true;
    //           } else {
    //             this.msgError(response.msg);
    //             return true;
    //           }
    //         });
    //       })
    //       .catch(() => {
    //         this.msgInfo("已取消");
    //       });
    //   }
    // },
    handlePortal(title, portal) {
      this.portaldialog.open = true;
      this.portaldialog.title = title;
      this.portaldialog.portal = { portal };
    },
    // 保存全编辑
    subEditAll() {
      let keys = this.columns
        .filter((item) => {
          if (item.fullEdit) return item;
        })
        .map((item) => item.prop);
      this.SortList(this.copy_table);
      let subData = filter2sub(keys, this.tableData, this.copy_table);
      if (subData.length == 0) {
        this.msgInfo("未修改任何数据");
        this.cancelEditAll();
      } else {
        updateData("/pmswbs/editAll", subData)
          .then((response) => {
            if (response.code == 200) {
              this.refreshCurrent();
              this.msgSuccess(response.msg);
            } else {
              this.tableData =
                this.copy_table.length > 0 ? deepClone(this.copy_table) : [];
              this.flag = true;
              this.msgError(response.msg);
            }
          })
          .catch(() => {
            this.tableData =
              this.copy_table.length > 0 ? deepClone(this.copy_table) : [];
            this.flag = true;
          });
      }
      this.editall = !this.editall;
      if (this.$refs.treeTable) this.$refs.treeTable.editall = this.editall;
      else this.$refs.dyTable.editall = this.editall;
    },
    //取消全编辑
    cancelEditAll() {
      this.editall = !this.editall;
      if (this.$refs.treeTable) this.$refs.treeTable.editall = this.editall;
      else this.$refs.dyTable.editall = this.editall;
      this.tableData =
        this.copy_table.length > 0 ? deepClone(this.copy_table) : [];
      this.flag = true;
    },
    // /** 新增按钮操作 */
    // handleAdd(url, str, title, sub = false) {
    //   this.addurl = url;
    //   this.getFormData(str, true);
    //   if (!sub) {
    //     this.form = {
    //       projectid: this.root.dataInfo.projectid
    //         ? this.root.dataInfo.projectid
    //         : this.root.dataInfo.id,
    //       parentid: this.root.parentid,
    //     };
    //     if (this.ids.length > 0) this.form["toid"] = Number(this.ids[0]);
    //     if (this.root.dataInfo.projectid) this.form["pmsid"] = this.projectid;
    //     this.open = true;
    //     this.title = title;
    //   } else {
    //     this.form = {
    //       projectid: this.dataInfo.projectid
    //         ? this.dataInfo.projectid
    //         : this.dataInfo.id,
    //       parentid: this.parentid,
    //       toid: this.form.toid,
    //       pmsid: this.form["pmsid"],
    //     };
    //     if (this.ids.length > 0) this.form["fromid"] = Number(this.ids[0]);
    //     if (this.dataInfo.projectid) this.form["pmsid"] = this.projectid;
    //     this.subopen = true;
    //     this.subtitle = title;
    //   }
    // },
    // /**  添加已存在*/
    // handleAddExited(obj) {
    //   let pageParams = eval("(" + obj.pageParams + ")");
    //   this.addurl = obj.url;
    //   this.table = pageParams.table;
    //   this.toolbar = pageParams.toolbar;
    //   this.command = pageParams.command;
    //   if(pageParams.search != undefined) this.search = pageParams.search;
    //   if (pageParams.getUrl.indexOf("{") != -1) {
    //     var url = pageParams.getUrl.substring(
    //       0,
    //       pageParams.getUrl.indexOf("{")
    //     );
    //     this.geturl = url + this.projectid;
    //   } else {
    //     this.geturl = pageParams.getUrl;
    //   }
    //   if (obj.sub) {
    //     this.form = {
    //       projectid: this.projectid,
    //       parentid: this.parentid,
    //       toid: this.form.toid,
    //       formid: this.ids[0],
    //       pmsid: this.form.pmsid,
    //     };
    //     this.subtopen = true;
    //     this.subtitle = obj.name;
    //   } else {
    //     this.copy_geturl = this.geturl;
    //     if (this.ids.length > 0)
    //       this.form = {
    //         projectid: this.dataInfo.projectid
    //           ? this.dataInfo.projectid
    //           : this.dataInfo.id,
    //         parentid: this.parentid,
    //         toid: this.ids[0],
    //       };
    //     else
    //       this.form = {
    //         projectid: this.dataInfo.projectid
    //           ? this.dataInfo.projectid
    //           : this.dataInfo.id,
    //         parentid: this.parentid,
    //       };
    //     if (this.dataInfo.projectid) this.form["pmsid"] = this.projectid;
    //     this.title = obj.name;
    //     this.topen = true;
    //   }
    // },
    // /** 添加已存在*/
    // handleAddAssign(obj) {
    //   if (this.ids.length == 0) {
    //     this.msgError("不能对没有选中进行此项操作！");
    //     return false;
    //   }
    //   if (this.level === 0) {
    //     this.ids[0] = 0;
    //   }
    //   let pageParams = eval("(" + obj.pageParams + ")");
    //   this.addurl = obj.url;
    //   this.table = pageParams.table;
    //   this.toolbar = pageParams.toolbar;
    //   this.command = pageParams.command;
    //   if(pageParams.search != undefined) this.search = pageParams.search;
    //   if (pageParams.getUrl.indexOf("{") != -1) {
    //     var url = pageParams.getUrl.substring(
    //       0,
    //       pageParams.getUrl.indexOf("{")
    //     );
    //     var substr = pageParams.getUrl.substring(
    //       pageParams.getUrl.indexOf("{") + 1,
    //       pageParams.getUrl.indexOf("}")
    //     );
    //     this.geturl = url + this.params.rowParams[substr];
    //   } else {
    //     this.geturl = pageParams.getUrl;
    //   }
    //   if (obj.sub) {
    //     this.form = {
    //       toid: this.form.toid,
    //       fromid: this.ids,
    //       projectid: this.projectid,
    //     };
    //     this.subtitle = obj.name;
    //     this.subtopen = true;
    //   } else {
    //     this.copy_geturl = this.geturl;
    //     this.form = {
    //       pmsid: this.ids.join(","),
    //       toid: this.ids.join(","),
    //       projectid: this.projectid,
    //     };
    //     this.title = obj.name;
    //     this.topen = true;
    //   }
    // },
    // /** 增加下层按钮操作 */
    // handleAddChild(url, str, title, sub = false) {
    //   this.addurl = url;
    //   if (this.ids.length !== 1) {
    //     this.msgError("不能对没有选中或者选中多个的数据进行此项操作！");
    //     return false;
    //   }
    //   if (this.level === 0) {
    //     this.form = {
    //       projectid: this.projectid,
    //       parentid: 0,
    //       level: this.level,
    //     };
    //   } else {
    //     this.form = {
    //       projectid: this.projectid,
    //       parentid: this.ids[0],
    //       level: this.level,
    //     };
    //   }
    //   this.getFormData(str, true);
    //   if (sub) {
    //     this.subtitle = title;
    //     this.subopen = true;
    //   } else {
    //     this.open = true;
    //     this.title = title;
    //   }
    // },
    // /** 修改按钮操作 */
    // handleUpdate(url, str, title, sub = false) {
    //   if (this.ids.length != 1) {
    //     this.msgInfo("请选择一条数据");
    //     return false;
    //   }
    //   this.addurl = url;
    //   this.getFormData(str);
    //   this.form = deepClone(this.selected[0]);
    //   this.open = true;
    //   this.title = val.title ? val.title : "编辑";
    //   // getData(this.addurl, this.ids[0]).then((response) => {
    //   //   this.form = response.data;
    //   //   this.open = true;
    //   //   this.title = val.title ? val.title : "编辑";
    //   // });
    // },
    // /** 删除按钮操作 */
    // handleDelete(url, title) {
    //   const ids = this.ids;
    //   this.$confirm(
    //     `是否确认${title} "${
    //       this.selected[0].name ||
    //       this.selected[0].title ||
    //       this.selected[0].fileName ||
    //       this.selected[0].folderName
    //     }" ${this.ids.length > 1 ? "等" : ""}?`,
    //     "警告",
    //     {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //     }
    //   )
    //     .then(function () {
    //       return delData(url, ids);
    //     })
    //     .then(() => {
    //       this.refreshCurrent();
    //       this.msgSuccess("删除成功");
    //     })
    //     .catch(function () {});
    // },
    // /** 升级降级操作 */
    // handleUpgrade(url) {
    //   const ids = this.ids;
    //   if (this.JugeSeletions().sameState) {
    //     this.$confirm('是否确认升级编号为"' + ids + '"的数据项?', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //     })
    //       .then(function () {
    //         return upgrade(url, ids);
    //       })
    //       .then(() => {
    //         this.refreshCurrent();
    //         this.msgSuccess("提升成功");
    //       })
    //       .catch(function () {});
    //   } else {
    //     this.msgError("请选择同一状态的数据！");
    //   }
    // },
    // /** 降级操作 */
    // handleDemotion(url) {
    //   const ids = this.ids;
    //   if (this.JugeSeletions().sameState) {
    //     this.$confirm('是否确认降级编号为"' + ids + '"的数据项?', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //     })
    //       .then(function () {
    //         return upgrade(url, ids);
    //       })
    //       .then(() => {
    //         this.refreshCurrent();
    //         this.msgSuccess("降级成功");
    //       })
    //       .catch(function () {});
    //   } else {
    //     this.msgError("请选择同一状态的数据！");
    //   }
    // },
    // /** 导出按钮操作 */
    // handleExport(url) {
    //   const queryParams = this.queryParams;
    //   this.$confirm("是否确认导出所有数据项?", "警告", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(function () {
    //       return exportData(url, queryParams);
    //     })
    //     .then((response) => {
    //       this.download(response.msg);
    //     })
    //     .catch(function () {});
    // },
    // openChanged(val) {
    //   this.loading = false;
    //   if (this.subopen) {
    //     this.subopen = false;
    //     if (this.addurl.indexOf("createRestrain") > -1) this.topenChanged(true);
    //     if (this.addurl.indexOf("pmsbatch") > -1) {
    //       this.refreshCurrent();
    //     }
    //   } else {
    //     this.open = false;
    //     if (val) {
    //       this.refreshCurrent();
    //     }
    //   }
    // },
    // topenChanged(val) {
    //   this.loading = false;
    //   if (this.subtopen) {
    //     this.subtopen = false;
    //     this.geturl = this.copy_geturl;
    //     this.$refs.addFormTable.getList(this.copy_geturl);
    //   } else {
    //     this.topen = false;
    //     if (val) {
    //       this.refreshCurrent();
    //     }
    //   }
    // },
    // editChanged(val) {
    //   this.addurl = val.url;
    //   this.form = {};
    //   if (val.url) {
    //     if (val.url != "/doc/UpdateFile") {
    //       if(typeof val.id != 'number'){
    //         this.form = val.id;
    //         this.open = true;
    //         this.title = val.title ? val.title : "编辑";
    //         this.getFormData(val.str);
    //       }else{
    //         getData(val.url, val.id).then((response) => {
    //           this.form = response.data;
    //           this.title = val.title ? val.title : "编辑";
    //           this.getFormData(val.str);
    //         });
    //       }
    //     } else {
    //       this.form = {
    //         id: val.id,
    //         fileList: [],
    //         projectid: this.projectid,
    //         parentid: this.parentid,
    //       };
    //       // this.open = true;
    //       this.title = val.title ? val.title : "编辑";
    //       this.getFormData(val.str);
    //     }
    //   } else {
    //     // this.open = true;
    //     this.title = val.title ? val.title : "编辑";
    //     this.getFormData(val.str);
    //   }
    // },
    openTable(val) {
      let pageParams = val.str;
      this.copy_url = this.addurl;
      this.addurl = val.url;
      this.table = pageParams.table;
      this.toolbar = pageParams.toolbar;
      this.command = pageParams.command;
      if (pageParams.getUrl.indexOf("{") != -1) {
        var url = pageParams.getUrl.substring(
          0,
          pageParams.getUrl.indexOf("{")
        );
        this.geturl = url + val.id;
      } else {
        this.geturl = pageParams.getUrl;
      }
      this.form = {
        toid: this.ids[0],
        projectid: this.projectid,
        pmsid: val.id,
      };
      if (val.sub) {
        this.subtopen = true;
        this.form["rowid"] = val.id;
        this.form["type"] = pageParams.type;
        this.subtitle = val.title ? val.title : "";
      } else {
        this.copy_geturl = this.geturl;
        this.topen = true;
        this.title = val.title ? val.title : "";
      }
    },
    closeTable(val) {
      let list = this.$refs.addFormTable.$refs.treeTable.GetList(
        this.form["rowid"]
      );
      list.params[this.form.type] =
        val.length > 0 ? val.map((item) => item.id).join(",") : "";
      list[this.form.type] =
        val.length > 0 ? val.map((item) => item.userName).join(",") : "";
      this.$refs.addFormTable.submitData[list.id] = {
        id: list.id,
        params: list.params,
        projectid: this.projectid,
      };
      this.addurl = this.copy_url;
      this.subtopen = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selected = selection;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      if (selection.length > 0) {
        if (selection[0].hasOwnProperty("level")) {
          this.level = selection[0].level;
        }
      }
    },
    // 节点单击事件
    handleNodeClick(data) {
      if (typeof data != "object") {
        this.$refs.dynamicTree.handleNodeClick(data);
        return;
      }
      this.parentid = 0;
      let pageParams = JSON.parse(data.pageParams.replace(/'/g, '"'));
      if (pageParams.command !== "" && pageParams.command !== undefined) {
        this.queryTreeParams.command = pageParams.command;
      }
      if (pageParams.table !== "" && pageParams.table !== undefined) {
        this.queryTreeParams.table = pageParams.table;
      }
      if (pageParams.form !== "" && pageParams.form !== undefined) {
        this.queryTreeParams.form = pageParams.form;
      }
      if (pageParams.toolbar !== "" && pageParams.toolbar !== undefined) {
        this.queryTreeParams.toolbar = pageParams.toolbar;
      }
      if (pageParams.searchForm !== "" && pageParams.searchForm !== undefined) {
        this.queryTreeParams.searchForm = pageParams.searchForm;
      }
      this.getTreeConfig();
      var url = data.url;
      this.queryParams = {
        pageNum: 1,
        pageSize: this.$store.state.user.pageSize||30,
      };
      if (url.indexOf("{") != -1) {
        var substr1 = url.substring(url.indexOf("?") + 1, url.indexOf("="));
        var substr2 = url.substring(url.indexOf("{") + 1, url.indexOf("}"));
        url = url.substring(0, url.indexOf("?"));
        this.queryParams[substr1] = data[substr2];
      }
      this.dataUrl = url;
      this.getList();
      if (data.parentid === -1) {
        this.parentid = 0;
      } else {
        this.parentid = data.id;
      }
    },
    /** 转换数据结构 */
    normalizer(node) {
      return {
        id: node.id,
        label: node.folderName,
        parentid: node.parentid,
        url: node.url,
        pageParams: node.pageParams,
      };
    },
    //保存
    handleSaveForm() {
      updateData("/" + this.$route.query.type, this.menuDataInfo)
        .then((response) => {
          if (response.code == 200) {
            this.msgSuccess(response.msg);
            this.dataInfo = deepClone(this.menuDataInfo);
            this.params.rowParams = deepClone(this.menuDataInfo);
            sessionStorage.setItem(
              "details" + this.projectid,
              JSON.stringify(this.params)
            );
            this.updateShow = false;
          } else {
            this.msgError(response.msg);
            this.menuDataInfo = deepClone(this.dataInfo);
            this.updateShow = false;
          }
        })
        .catch(() => {
          this.menuDataInfo = deepClone(this.dataInfo);
          this.updateShow = 1;
        });
    },
    SetFlag() {
      this.flag = false;
    },
    setIds(val) {
      this.ids = val;
    },
    // 打开右键菜单
    Opencontextmenu(e) {
      this.contextmenu.left =
        e.clientX - 100 < 0
          ? 0
          : document.body.clientWidth - e.clientX < 100
          ? document.body.clientWidth - 200
          : e.clientX - 100;
      this.contextmenu.top =
        document.body.clientHeight - e.clientY < 250
          ? e.clientY - 170
          : e.clientY - 80;
      this.contextmenu.visible = true;
    },
    Closecontextmenu() {
      this.contextmenu.visible = false;
    },
    // 任务复制||剪切
    /*
      type:类型 copy 复制 cut 剪切
      */
    copy(type = "copy") {
      if (this.ids == 0) {
        this.msgInfo("未选择任何数据");
      } else {
        this.copy_ids = [];
        this.pasteType = type == "copy" ? 1 : 2;
        for (let id of this.ids) {
          let tabledata = deepClone(this.tableData);
          let list = this.$refs.treeTable.GetList(id);
          list.checked = false;
          list[type] = true;
          this.copy_ids = this.copy_ids.concat(
            tabledata.splice(list.rowIndex, list.allChildren.length + 1)
          );
          this.$refs.treeTable.HandleCheckedChange(list);
        }
      }
    },
    // 任务粘贴
    /*
        level:级别 0 同级 1 子级
      */
    paste(level = 1) {
      if (this.ids.length != 1) {
        this.msgInfo("请选择一项任务");
        return false;
      } else {
        let current = this.$refs.treeTable.GetList(this.ids[0]);
        for (let index = 0; index < this.copy_ids.length; index++) {
          let list = this.copy_ids[index];
          list.paste = true;
          list.id = list.id + this.tableData.length;
          let oldLevel = Number(list.level);
          let oldRank = list.rank.trim();
          list.level = current.level + level;
          if (level == 0) {
            list.parentid = Number(current.parentid);
            let parent = this.$refs.treeTable.GetList(current.parentid);
            list.rank = parent.rank
              ? parent.rank.trim() +
                "." +
                String(Number(parent.children.length) + Number(index) + 1)
              : String(Number(parent.children.length) + Number(index) + 1);
          } else {
            list.parentid = Number(current.id);
            list.rank =
              current.rank.trim() +
              "." +
              String(Number(current.children.length) + Number(index) + 1);
          }
          this.subPasteData.push({
            fromid: String(list.id - this.tableData.length),
            toid: list.parentid,
            type: this.pasteType,
          });
          if (list.allChildren.length > 0) {
            let parentid = [list.id];
            index++;
            for (let i in list.allChildren) {
              let row = this.copy_ids[Number(index) + Number(i)];
              row.paste = true;
              row.id = row.id + this.tableData.length;
              parentid[row.level - oldLevel] = row.id;
              row.parentid = parentid[row.level - oldLevel - 1];
              row.level = list.level + row.level - oldLevel;
              row.rank = row.rank.replace(oldRank, list.rank);
            }
            index += list.allChildren.length - 1;
          }
          this.$refs.treeTable.defaultExpand.push(current.id);
          this.ids = [];
          sessionStorage.setItem(
            "expand" + this.$route.query.type + this.$route.params.Id,
            JSON.stringify(this.$refs.treeTable.defaultExpand)
          );
        }
        this.tableData.splice(
          Number(current.rowIndex + 1 + current.allChildren.length),
          0,
          ...this.copy_ids
        );
        this.flag = true;
        this.$refs.treeTable.toggle = !this.$refs.treeTable.toggle;
      }
    },
    // 保存粘贴数据
    submit() {
      addData("/pmswbs/copywbs", this.subPasteData)
        .then((response) => {
          if (response.code == 200) {
            this.msgSuccess(response.msg);
            this.getMenuConfig();
          } else {
            this.msgError(response.msg);
            this.tableData = deepClone(this.copy_table);
          }
        })
        .catch(() => {
          this.tableData = deepClone(this.copy_table);
        });
      this.copy_ids = [];
      this.subPasteData = [];
      this.flag = true;
    },
    reset() {
      this.tableData =
        this.copy_table.length > 0 ? deepClone(this.copy_table) : [];
      this.copy_ids = [];
      this.subPasteData = [];
      this.flag = true;
    },
    // 批量编辑
    handleBatch(obj, addForm, table) {
      this.title = "批量编辑";
      if (this.ids.length == 0) {
        this.msgInfo("请选择修改数据行");
      } else {
        if (this.ids.indexOf(Number(this.projectid)) > -1) {
          this.msgInfo("批量编辑不支持项目的修改");
        } else {
          this.getFormData(addForm);
          this.table = "form_col";
          this.addurl = obj.url;
          this.geturl = table;
          this.topen = true;
        }
      }
    },
    subBatch(addform) {
      this.subtitle = "批量编辑";
      this.topen = false;
      for (let col of addform) {
        let current = this.addFormData.filter((item) => {
          return item.prop == col.prop;
        });
        if (current.length > 0) col = current[0];
      }
      this.form["ids"] = this.ids.join(",");
      this.addFormData = addform;
      this.subopen = true;
    },
    // //获取表单数据
    // getFormData(str, flag) {
    //   let formData = {};
    //   let optionData = JSON.parse(sessionStorage.getItem("optionsData"));
    //   getAddForm({ addForm: str }).then((response) => {
    //     // formData = response.data;
    //     this.addFormData = this.formDataUpdate(response.data);
    //     if (flag) {
    //       for (let item of this.addFormData) {
    //         // console.log(this.dataInfo)
    //         if (this.form[item.prop] == undefined && item.defaultValue) {
              // console.log(item.defaultValue.replaceAll('$',''))
    //           if(item.defaultValue.indexOf('$')>-1)
    //             this.$set(this.form, item.prop,this.dataInfo[item.defaultValue.replaceAll('$','')]);
    //           else
    //             this.$set(this.form, item.prop,item.defaultValue)
    //         }
    //       }
    //     }
    //     this.open = true;
    //   });
    // },
    // formDataUpdate(data) {
    //   let optionData = JSON.parse(sessionStorage.getItem("optionsData"));
    //   let formData = data;
    //   formData.forEach((item, index) => {
    //     if (
    //       item.componentType === "el-select" ||
    //       item.componentType === "el-selects" ||
    //       item.componentType === "el-radio" ||
    //       item.componentType === "el-checkbox-group"
    //     ) {
    //       if (
    //         item.prop === "policyid" ||
    //         item.prop === "stateid" ||
    //         item.prop === "ownerid"
    //       ) {
    //         formData[index].optionValue = optionData[item.optionValue];
    //       } else {
    //         if (
    //           this.tempDicts[item.prop] &&
    //           this.tempDicts[item.prop].length > 0
    //         ) {
    //           formData[index].optionValue = this.selectNormalizer(
    //             deepClone(this.tempDicts[item.prop])
    //           );
    //           let tempDicts = JSON.parse(sessionStorage.getItem("tempDicts"));
    //           tempDicts[item.prop] = deepClone(this.tempDicts[item.prop]);
    //           sessionStorage.setItem("tempDicts", JSON.stringify(tempDicts));
    //         } else {
    //           if (item.optionValue) {
    //             if (item.optionValue.indexOf("url") > -1) {
    //               let url = this.getUrl(item.optionValue.split(":")[1]);
    //               let appendid = this.$route.params.Id;
    //               if (item.optionValue.indexOf("{") > -1) {
    //                 if (this.$route.query.type.indexOf("pmswbs") > -1) {
    //                   appendid = this.dataInfo.projectid;
    //                 }
    //                 if (
    //                   this.tempDicts[item.prop + "-" + appendid] == undefined
    //                 ) {
    //                   getDataList(url).then((response) => {
    //                     this.tempDicts[item.prop + "-" + appendid] =
    //                       response.rows;
    //                     let tempDicts = JSON.parse(
    //                       sessionStorage.getItem("tempDicts")
    //                     );
    //                     tempDicts[item.prop + "-" + appendid] = deepClone(
    //                       response.rows
    //                     );
    //                     sessionStorage.setItem(
    //                       "tempDicts",
    //                       JSON.stringify(tempDicts)
    //                     );
    //                   });
    //                 } else {
    //                   let tempDicts = JSON.parse(
    //                     sessionStorage.getItem("tempDicts")
    //                   );
    //                   tempDicts[item.prop + "-" + appendid] = deepClone(
    //                     this.tempDicts[item.prop + "-" + appendid]
    //                   );
    //                   sessionStorage.setItem(
    //                     "tempDicts",
    //                     JSON.stringify(tempDicts)
    //                   );
    //                 }
    //               } else if (this.tempDicts[item.prop] == undefined) {
    //                 getDataList(url).then((response) => {
    //                   // if (response.code == 200) {
    //                   this.tempDicts[item.prop] = deepClone(response.rows);
    //                   let tempDicts = JSON.parse(
    //                     sessionStorage.getItem("tempDicts")
    //                   );
    //                   tempDicts[item.prop] = deepClone(response.rows);
    //                   sessionStorage.setItem(
    //                     "tempDicts",
    //                     JSON.stringify(tempDicts)
    //                   );
    //                   formData[index].optionValue = response.rows;
    //                   if (response.rows && response.rows.length == 1) {
    //                     // console.log(response.rows)
    //                     this.form[item.prop] = response.rows[0].id;
    //                   }
    //                   // }
    //                 });
    //               }
    //             } else {
    //               this.getDicts(item.optionValue).then((response) => {
    //                 this.tempDicts[item.prop] = deepClone(response.data);
    //                 formData[index].optionValue = this.selectNormalizer(
    //                   response.data
    //                 );
    //               });
    //             }
    //           } else if (item.show && this.form.id) {
    //             getDataList(this.getUrl(item.show, this.form)).then(
    //               (response) => {
    //                 if (response.code == 200) {
    //                   item.optionValue = response.rows;
    //                 }
    //               }
    //             );
    //           }
    //         }
    //       }
    //     }
    //     if (item.componentType === "el-cascader") {
    //       let optionarr = item.optionValue.split("?");
    //       if (optionarr.length > 1) {
    //         this.optionNormalizer(optionData[optionarr[0]]);
    //         let typearr = [];
    //         optionData[optionarr[0]].forEach((titem) => {
    //           if (titem.value === parseInt(optionarr[1])) {
    //             typearr.push(titem);
    //             formData[index].optionValue = typearr;
    //           }
    //         });
    //       } else {
    //         formData[index].optionValue = this.optionNormalizer(
    //           optionData[item.optionValue]
    //         );
    //       }
    //     }
    //     if (item.componentType === "el-add-existing") {
    //       if (item.prop == "productName" || item.prop == "productCode") return;
    //       let appendid = this.$route.params.Id;
    //       if (this.$route.query.type.indexOf("pmswbs") > -1) {
    //         appendid = this.dataInfo.projectid;
    //       }
    //       let pageParams = eval("(" + item.show + ")");
    //       let type = pageParams.type;
    //       let geturl = pageParams.getUrl;
    //       if (geturl.indexOf("{") > -1) {
    //         if (this.tempDicts[item.prop + "-" + appendid]) {
    //           let tempDicts = JSON.parse(sessionStorage.getItem("tempDicts"));
    //           tempDicts[item.prop + "-" + appendid] = deepClone(
    //             this.tempDicts[item.prop + "-" + appendid]
    //           );
    //           item.optionValue = deepClone(
    //             tempDicts[item.prop + "-" + appendid]
    //           );
    //           sessionStorage.setItem("tempDicts", JSON.stringify(tempDicts));
    //         } else {
    //           geturl = this.getUrl(pageParams.getUrl, { projectId: appendid });
    //           getDataList(geturl).then((res) => {
    //             let tempDicts = JSON.parse(sessionStorage.getItem("tempDicts"));
    //             if (res.rows && res.rows.length > 0) {
    //               tempDicts[item.prop + "-" + appendid] = deepClone(res.rows);
    //               if (type == "split_tree_table") {
    //                 for (let i of res.rows) {
    //                   getDataList(this.getUrl(pageParams.expandUrl, i), {
    //                     loginUser:
    //                       sessionStorage.getItem("loginUser") ||
    //                       this.$store.state.user.userid,
    //                   }).then((response) => {
    //                     if (pageParams.expandUrl.indexOf("enovia") > -1) {
    //                       response = JSON.parse(response)
    //                     }
    //                     tempDicts[item.prop + "-" + appendid] = tempDicts[
    //                       item.prop + "-" + appendid
    //                     ].concat(response.rows);
    //                     item.optionValue = deepClone(
    //                       tempDicts[item.prop + "-" + appendid]
    //                     );
    //                     sessionStorage.setItem(
    //                       "tempDicts",
    //                       JSON.stringify(tempDicts)
    //                     );
    //                     this.tempDicts[item.prop + "-" + appendid] = deepClone(
    //                       tempDicts[item.prop + "-" + appendid]
    //                     );
    //                   });
    //                 }
    //               }else{
    //                 item.optionValue = deepClone(
    //                   tempDicts[item.prop + "-" + appendid]
    //                 );
    //                 sessionStorage.setItem(
    //                   "tempDicts",
    //                   JSON.stringify(tempDicts)
    //                 );
    //                 this.tempDicts[item.prop + "-" + appendid] = deepClone(
    //                   tempDicts[item.prop + "-" + appendid]
    //                 );
    //               }
    //             }
    //           });
    //         }
    //       } else {
    //         // geturl = this.getUrl(pageParams.getUrl);
    //         if (this.tempDicts[item.prop]==undefined) {
    //           getDataList(geturl).then((res) => {
    //             let tempDicts = JSON.parse(sessionStorage.getItem("tempDicts"));
    //             if (res.rows && res.rows.length > 0) {
    //               tempDicts[item.prop] = deepClone(res.rows);
    //               if (type == "split_tree_table") {
    //                 for (let i of res.rows) {
    //                   getDataList(this.getUrl(pageParams.expandUrl, i), {
    //                     loginUser:
    //                       sessionStorage.getItem("loginUser") ||
    //                       this.$store.state.user.userid,
    //                   }).then((response) => {
    //                     if (pageParams.expandUrl.indexOf("enovia") > -1) {
    //                       response = JSON.parse(response)
    //                     }
    //                     tempDicts[item.prop] = tempDicts[item.prop].concat(
    //                       response.rows
    //                     );
    //                     item.optionValue = deepClone(tempDicts[item.prop]);
    //                     sessionStorage.setItem(
    //                       "tempDicts",
    //                       JSON.stringify(tempDicts)
    //                     );
    //                     this.tempDicts[item.prop] = deepClone(tempDicts[item.prop]);
    //                   });
    //                 }
    //               }else{
    //                 item.optionValue = deepClone(tempDicts[item.prop]);
    //                 sessionStorage.setItem(
    //                   "tempDicts",
    //                   JSON.stringify(tempDicts)
    //                 );
    //                 this.tempDicts[item.prop] = deepClone(tempDicts[item.prop]);
    //               }
    //             }
    //           });
    //         } else {
    //           item.optionValue = deepClone(this.tempDicts[item.prop]);
    //           let tempDicts = JSON.parse(sessionStorage.getItem("tempDicts"));
    //           tempDicts[item.prop] = deepClone(this.tempDicts[item.prop])
    //           sessionStorage.setItem(
    //                 "tempDicts",
    //                 JSON.stringify(tempDicts)
    //               );
    //         }
    //       }
    //       // let formtype = pageParams.type;
    //       // getDataList(geturl).then(res=>{
    //       //   console.log(res)
    //       // })
    //     }
    //   });
    //   return formData;
    // },
    // /** 转换选项数据结构 */
    // optionNormalizer(data) {
    //   data.forEach((item, index) => {
    //     data[index] = {
    //       value: item.id,
    //       label: item.description,
    //       parentid: item.parentid,
    //     };
    //   });
    //   return this.handleTree(data, "value");
    // },
    // /** 转换选项数据结构 */
    // selectNormalizer(data) {
    //   data.forEach((item, index) => {
    //     data[index] = {
    //       id: item.dictValue,
    //       description: item.dictLabel,
    //     };
    //   });
    //   return data;
    // },
    handleToggleExpand() {
      this.isFullscreen = !this.isFullscreen;
      if (this.$parent.isexpand) {
        this.$parent.isexpand = 0;
      } else {
        this.$parent.isexpand = this.portalItemId;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  margin: 0;
  padding: 0;
  position: relative;
}
.collapesbutton {
  width: 14px;
  position: absolute;
  top: 0;
  bottom: 0;
  padding: 0;
  border: none;
  margin: auto 0;
  z-index: 200;
}
.treeMenu {
  background-color: #f8f8f8;
  height: 100%;
  position: relative;
}
.el-menu-item {
  border-bottom: 1px solid #dcdfe6;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.treeMenu .el-tabs--border-card {
  height: 100%;
}
.app-container .head-container {
  padding-left: 5px;
  padding-right: 5px;
  border-top: 1px solid #d8d8d8;
}

.el-tabs__item {
  height: 30px;
  line-height: 30px;
}
.page-title {
  background: #fff;
  /*border: 1px solid #D8D8D8;*/
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
  /*margin-bottom: 5px;*/
}
.headerContent {
  float: left;
  padding: 20px 0 10px;
  width: 100%;
}
.extendedHeader {
  display: block;
  line-height: 23px;
  white-space: nowrap;
}
.extendedHeader.name {
  font-size: 16px;
  font-weight: bold;
  font-family: "3dsregular", Arial, Helvetica, sans-serif;
  max-width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-indent: 20px;
}
.extendedHeader.content {
  font-size: 13px;
  max-width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  float: left;
}
.extendedHeader.fromTitle {
  font-size: 13px;
  width: 150px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.inline-block {
  display: inline-block;
  margin-right: 20px;
}
.infinite-list {
  list-style: none;
  padding: 5px;
  margin: 0;
}
.infinite-list-item {
  list-style: none;
  padding: 5px;
  margin: 0;
  background-color: #f8f8f8;
  border-bottom: 1px solid #d8d8d8;
  position: relative;
}
.infinite-list-item.selected {
  list-style: none;
  padding: 5px;
  margin: 0;
  background-color: #fff;
  border-bottom: 1px solid #d8d8d8;
  position: relative;
}
.el-dropdown {
  padding: 10px;
}
.mainContent {
  float: left;
  width: 100%;
  height: 100%;
}
.extendedMain {
  display: block;
  line-height: 23px;
  white-space: nowrap;
  border-bottom: #d8d8d8 solid 1px;
}
.extendedMain.name {
  font-size: 16px;
  font-weight: bold;
  font-family: "3dsregular", Arial, Helvetica, sans-serif;
  max-width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.extendedMain.content {
  font-size: 13px;
  width: 300px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 5px 0 5px 10px;
}
.extendedMain.fromTitle {
  font-size: 13px;
  width: 150px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 5px 0 5px 10px;
  background-color: #f8f8f8;
}
.flex {
  display: flex;
}
.contextmenu {
  margin: 0;
  background: #fff;
  z-index: 3000;
  position: absolute;
  list-style-type: none;
  padding: 5px 0;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 400;
  color: #333;
  box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
  li {
    margin: 0;
    padding: 7px 16px;
    cursor: pointer;
    &:hover {
      background: #eee;
    }
  }
}
//去掉最上级的before  after 即是去电最上层的连接线
/deep/ .el-tree > div {
  &::before {
    display: none;
  }
  &::after {
    display: none;
  }
}
</style>
